package Control;

import java.util.ArrayList;
import java.util.Iterator;

import Entity.MsgPackage;
import GUI.*;

/**
* Controls the instance of Edit Request Stage Manager
* This class sends and gets data from the server 
* and display it on the panel.
* @author Nofar
*
*/ 
public class EditReqStageMangerControl {

	private EditRequestStageManager_GUI editManger_gui;
	private EstimationStage_GUI stage1;
	private ExaminationStage_GUI stage2;
	private performanceStage_GUI stage3;
	private TestingStage_GUI stage4;
	private MsgPackage editMsg;
	private  String [] reqANDstage;
	
	/**
	 * the constructor
	 */
	public EditReqStageMangerControl()
	{
	editManger_gui = new EditRequestStageManager_GUI();
	stage1= new EstimationStage_GUI();
	stage2= new ExaminationStage_GUI();
	stage3= new performanceStage_GUI();
	stage4= new TestingStage_GUI();
	editMsg= new MsgPackage(); 
	reqANDstage = new String[2];
	}
	
	/**
	 * 
	 * @return EditRequestStageManager_GUI
	 */
	public EditRequestStageManager_GUI getEditMangerGui(){
		return editManger_gui;
	}
/**
 * this method check if the current user has authorization for the wanted step
 * @return
 */
	/**
	 * this method check if the current user has authorization for the wanted step
	 * @return
	 */
	public int checkPer(){
		reqANDstage[0]=(String) editManger_gui.getReqNum().getSelectedItem().toString();
		reqANDstage[1]=(String) editManger_gui.getStagename().getSelectedItem().toString();
		int StageNum = getNumStage(reqANDstage[1]);
		//if(ScreenManager.getUserName().getRole()!=4 || ScreenManager.getUserName().getRole()!=3){
		if(StageNum!=6 && StageNum!=9){	
			ArrayList<Integer> temp = new ArrayList<Integer>();
			temp = ScreenManager.getUserName().getReq_auto_list().get(StageNum);
			Iterator<Integer> it = temp.iterator();
			while(it.hasNext()){
				if(Integer.parseInt(reqANDstage[0])== it.next())
					return StageNum;
			}
		}
		else
			return StageNum;
		return 0;
	}
	
	
	public int getNumStage(String name){
		if(name.equals("estimation"))
			return 5;
		else if(name.equals("examination"))
			return 6;
		else if(name.equals("performance"))
			return 7;
		else
			return 9;
	}
	/**
	 * This method sends the request number and  stage number
	 *  to the  server and receive an answer (received from query from database) 
	 *  and the control display it in a message
	 */
	public void ExtentionRequest_pressed(String ReqNum,String StageNum){
		
	}
	
	public void setEditManger_gui(EditRequestStageManager_GUI editManger_gui) {
		this.editManger_gui = editManger_gui;
	}
	public MsgPackage getEditMsg() {
		return editMsg;
	}
	
	public EstimationStage_GUI getStage1() {
		return stage1;
	}

	public ExaminationStage_GUI getStage2() {
		return stage2;
	}

	public performanceStage_GUI getStage3() {
		return stage3;
	}

	public TestingStage_GUI getStage4() {
		return stage4;
	}

	public void setEditMsg(MsgPackage editMsg) {
		this.editMsg = editMsg;
	}

	public String[] getReqANDstage() {
		return reqANDstage;
	}
	


}
